package com.zhiwang.planet.mvvm.model.request

import com.google.gson.annotations.SerializedName
import okhttp3.MediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody
import java.io.File


data class LaunchRequestBody(var plat: String, var device: String)

//针对有些情况必须随便传一个值
class NonsenseRequest(var nothing: String = "1")


//绑定支付宝账户
class BindAliAccountRequest(@SerializedName("alipay") var aliAccount: String,
                            @SerializedName("alipay_name") var realName: String,
                            @SerializedName("tu_vcode") var graphCode: String,
                            @SerializedName("vcode") var smsCode: String)

//登录
class LoginRequest(@SerializedName("username") var phone: String,
                   @SerializedName("vcode") var sms: String,
                   @SerializedName("deviceid") var imei: String,
                   @SerializedName("get_token")
                   var get_token: Int = 1,
                   @SerializedName("os_version")
                   var androidVersion: String,
                   @SerializedName("versionname")
                   var appVersionName: String,
                   @SerializedName("wifi")
                   var wifiName: String,
                   @SerializedName("model")
                   var deviceModel: String
) {

    @SerializedName("phone")
    var ss = phone
    var code: String? = null
}

//登出
class LogoutRequest(var act: String = "logout")

//上传设备号
class DeviceIdRequest(
        @SerializedName("deviceid")
        var deviceId: String,
        @SerializedName("userid")
        var userid: String)


//获取注册短信验证码
class SmsCodeRequest(
        @SerializedName("phone") var phone: String,
        @SerializedName("tu_vcode") var graphCode: String,
        @SerializedName("tu_token") var randomStr: String) {

    @SerializedName("vcode_type")
    lateinit var type: String

    fun setTypeRegister() {
        type = "app_reg"
    }

    fun setTypePhoneBind() {
        type = "app_bindphone"
    }

    fun setTypeFind() {
        type = "app_findpwd"
    }

    fun setTypeChange() {
        type = "app_changepwd"
    }

    fun setTypeBind() {
        type = "app_bind"
    }

    fun setTypeBindNoPic() {
        type = "app_bind_no_pic"
    }

    fun setTypeLogin() {
        type = "login_vcode"
    }

    fun setTypeLoginReg() {
        type = "login_reg"
    }
}


data class SmsReq(@SerializedName("phone") var phone: String) {

    @SerializedName("vcode_type")
    lateinit var type: String

    fun setTypeRegister() {
        type = "app_reg"
    }

    fun setTypeRegisterV2() {
        type = "app_reg_all"
    }

    fun setTypeWxBindPhone() {
        type = "wx_bind_phone"
    }

    fun setTypePhoneBind() {
        type = "app_bindphone"
    }

    //更换绑定手机号
    fun setTypeChangeBindPhone() {
        type = "change_phone"
    }

    fun setTypeFind() {
        type = "app_findpwd"
    }

    fun setTypeChange() {
        type = "app_changepwd"
    }

    fun setTypeBind() {
        type = "app_bind"
    }

    fun setTypeBindNoPic() {
        type = "app_bind_no_pic"
    }

    fun setTypeLogin() {
        type = "login_vcode"
    }

    fun setTypeLoginReg() {
        type = "login_reg"
    }
}

//获取修改密码短信验证码
class ChangeCaptchaRequest(@SerializedName("") var vcode: String,
                           @SerializedName("") var type: String = "app_change")

//获取找回密码短信验证码
class FindCaptchaRequest(@SerializedName("") var vcode: String,
                         @SerializedName("") var type: String = "app_find")

class ChangePasswordRequest(@SerializedName("phone") var phone: String,
                            @SerializedName("password") var pwd: String,
                            @SerializedName("vcode") var smscode: String,
                            @SerializedName("change_type") var type: String = "app_changepwd")


class FindPasswordRequest(@SerializedName("phone") var phone: String,
                          @SerializedName("password") var pwd: String,
                          @SerializedName("vcode") var smscode: String,
                          @SerializedName("find_type") var type: String = "app_findpwd")

class DiamondCollectRequest private constructor(var id: String) {
    companion object {
        val INSTANCE = DiamondCollectRequest("")

        fun create(id: String): DiamondCollectRequest {
            INSTANCE.id = id
            return INSTANCE
        }
    }
}


class RegisterRequest(@SerializedName("vcode") var sms: String,
                      @SerializedName("phone") var phone: String,
                      @SerializedName("password") var pwd: String,
                      @SerializedName("reg_type") var type: String = "app_reg")


class FeedBackRequest(@SerializedName("title") var title: String,
                      @SerializedName("content") var content: String,
                      @SerializedName("lianxi") var phone: String)

class FeedBackRequest2 {

    companion object {
        fun create(title: String, content: String, files: List<File>): HashMap<String, RequestBody> {


            val res = hashMapOf<String, RequestBody>()

            val titlePart =
                    RequestBody.create(null, title)

            val contentPart =
                    RequestBody.create(null, content)


            res["type"] = titlePart
            res["content"] = contentPart


//            val builder = MultipartBody.Builder()
//                    .addPart(MultipartBody.Part.createFormData("title", title))
//                    .addPart(MultipartBody.Part.createFormData("content", content))

            files.forEachIndexed { index, f ->

                val key = String.format("%1\$s\"; filename=\"%1\$s", "photo_" + (index + 1).toString())
                val part = RequestBody.create(MediaType.parse("multipart/form-data"), f)

                res[key] = part
            }

            return res


        }
    }
}

class WithDrawRequest(@SerializedName("number") var cash: String,
                      @SerializedName("pay_passwd") var payPwd: String) {
    @SerializedName("cash_type")
    lateinit var type: String

    fun setTypeWx() {
        type = "weixin"
    }

    fun setTypeAlipay() {
        type = "alipay"
    }
}

class PageIndexRequest(@SerializedName("page") var pageIndex: Int, var nothing: String = "1",
                       var type: String? = null)

class ChangePayPasswordRequest(
        @SerializedName("pay_passwd")
        var payPassword: String,
        @SerializedName("vcode")
        var smsCode: String)

//
class RedundantRequest(var nothing: String? = "php lame")


/*开通vip*/
class VipRequest(@SerializedName("userid")
                 var userid: String,
                 @SerializedName("vip_type")
                 var vipType: String,
                 @SerializedName("pay_type")
                 var payType: String,
                 var pay_platform: Int = 0)

class AliPaySign(var sign: String, var tradeno: String)

class KmRequest(var id: String, var pay_passwd: String)

class BindWxRequest(
        var phone: String = "",
        @SerializedName("vcode")
        var sms: String = "",
        var password: String = "",
        var openid: String = "",
        var direct: String = "",
        var deviceid: String = "") {

    lateinit var act: String

    fun setTypeBinOldUser() {
        act = "bind_user"
    }

    fun setTypeBindPhone() {
        act = "bind_phone"
    }

    fun setTypeCreateNew() {
        act = "bind_direct"
    }
}

data class BindPhoneRequest(var phone: String,
                            @SerializedName("vcode")
                            var sms: String)

data class GamePlayTimeReport(
        @SerializedName("data1")
        var gameId: String,
        @SerializedName("data2")
        var gamePlayedTimeSeconds: Int,
        @SerializedName("data3") //根据 gameId+gamePlayTimeSeconds+token拼接起来的字符串的md5
        var digest: String? = "")


data class AppUsageTaskRequest(
        @SerializedName("taskid")
        var taskId: String)

/**
 * frirnd_id:
use_uid: 30003
km_list: 11111111111111111111*22222222222
22222222*33333333
 */
data class WelfareExchange(
        @SerializedName("frirnd_id")
        var friendId: String,
        @SerializedName("use_uid")
        var userid: String,
        @SerializedName("km_list")
        var kmList: String
)

